import moment from "../../utils/moment.js";
const app = getApp()
Page({
    data: {
        tabs: ["选项一", "选项二", "选项三"],
        scrollTop: 100,
        background: ['cloud://tangbohao-43a8cc.7461-tangbohao-43a8cc/微信图片_20190519220714.jpg', 'cloud://tangbohao-43a8cc.7461-tangbohao-43a8cc/微信图片_20190519220711.jpg', 'cloud://tangbohao-43a8cc.7461-tangbohao-43a8cc/微信图片_20190519220706.jpg'],
        navs: [
            {
                icon: "../../images/icon-new-list1.png",
                name: "食品",
                product_type: 10
            },
            {
                icon: "../../images/icon-new-list2.png",
                name: "日用",
                product_type: 11
            },
            {
                icon: "../../images/icon-new-list3.png",
                name: "服饰",
                product_type: 12
            },
            {
                icon: "../../images/icon-new-list4.png",
                name: "电器",
                product_type: 13
            }
        ],
        goods: [],
        hotProducts: []
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function() {
        //显示加载界面
        wx.showLoading({
            title: '加载中',
            mask: true
        })
        ////// 检测小程序兼容性
        if (!wx.cloud) {
            wx.redirectTo({
                url: '../chooseLib/chooseLib',
            })
            return
        }
        const db = wx.cloud.database()
        //获取商品列表
        db.collection('product_list').get({
            //回调
            success: res => {
                this.setData({
                    hotProducts: res.data,
                    goods: res.data
                })
                wx.hideLoading()
            },
            fail: err => {
                wx.hideLoading()
                wx.showToast({
                    icon: 'none',
                    title: '查询记录失败'
                })
                console.error('[数据库] [查询记录] 失败：', err)
            }
        })
    },
    doSearch(e) {
        wx.navigateTo({
            url: `/pages/goodsList/goodsList?keyWord=${e.detail}`
        })
    },
});